<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="/view/template.xhtml">
        <ui:define name="head">
            <script type="text/javascript">
                    function handleSaveRequest(xhr, status, args) {
                            if(args.success) {
                                    leadDialog.hide();
                            } else if(args.duplicate ){
                                    accountDialog.show();
                                     leadDialog.hide();
                            }
                    }
            </script>
        </ui:define>
        <ui:define  name="content">
            <f:view>
                <h:form id ="form1">
                    <p:dataTable value="#{leadManager.leads}" var="item" id="leads" paginator="true" rows="20" paginatorPosition="bottom"
                                 selectionMode="single" selection="#{leadManager.selectedLead}"
                                 update="form2:display" onselectComplete="leadDialog.show()">
                        <f:facet name="header">
                            <h:panelGrid columns="2" >
                                <p:breadCrumb preview="true" expandEffectDuration="200" previewWidth="20" style="width:500px" expandedBeginningItems="1" expandedEndItems="0">
                                    <p:menuitem value="选项"/>
                                    <p:menuitem value="新增客流量" actionListener="#{leadManager.createLead}" oncomplete="leadDialog.show();" update="form2:display"/>
                                    <p:menuitem value="查询客户并新增客流量" actionListener="#{leadManager.createLead}" oncomplete="accountDialog.show();" update="form2:display"/>
                                    <p:menuitem value="今日客流量" actionListener="#{leadManager.findToday}" update="form1:leads"/>
                                    <p:menuitem value="本周客流量" actionListener="#{leadManager.findWeek}" update="form1:leads"/>
                                    <p:menuitem value="本月客流量" actionListener="#{leadManager.findMonth}" update="form1:leads"/>
                                </p:breadCrumb>
                                <h:panelGrid columns="4" style="width: 300px">
                                    <h:outputLabel value="模糊查询"></h:outputLabel>
                                    <h:inputText value="#{leadManager.searchContent}" title="可输入部分男宾或女宾的姓名与电话进行查询"></h:inputText>
                                    <p:commandLink update="form1:leads" actionListener="#{leadManager.search}">
                                        <p:graphicImage value="/resources/images/search.png"/>
                                    </p:commandLink>
                                    <p:ajaxStatus  style="width:16px;height:16px;">
                                        <f:facet name="start">
                                            <h:graphicImage  value="/resources/images/ajaxloading.gif" />
                                        </f:facet>
                                        <f:facet name="complete">
                                            <h:outputText value=""/>
                                        </f:facet>
                                    </p:ajaxStatus>

                                </h:panelGrid>

                            </h:panelGrid>
                        </f:facet>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="序号"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="男宾姓名"/>
                            </f:facet>
                            <h:outputText value="#{item.account.mname}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="男宾电话"/>
                            </f:facet>
                            <h:outputText value="#{item.account.mphone}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="女宾姓名"/>
                            </f:facet>
                            <h:outputText value="#{item.account.fname}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="女宾电话"/>
                            </f:facet>
                            <h:outputText value="#{item.account.fphone}">

                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="固定电话"/>
                            </f:facet>
                            <h:outputText value="#{item.account.phone}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="结婚日期"/>
                            </f:facet>
                            <h:outputText value="#{item.account.marriageDate}">
                               <f:convertDateTime pattern="yyyy-MM-dd" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="客户来源"/>
                            </f:facet>
                            <h:outputText value="#{item.source}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="来店意向"/>
                            </f:facet>
                            <h:outputText value="#{item.inclination}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="侧重点"/>
                            </f:facet>
                            <h:outputText value="#{item.emphasis}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="客户级别"/>
                            </f:facet>
                            <p:rating id="rating" value="#{item.rating}" disabled="true"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="来访时间"/>
                            </f:facet>
                            <h:outputText value="#{item.visitTime}">
                                <f:convertDateTime pattern="yyyy-MM-dd" />
                            </h:outputText>
                        </p:column>
                    </p:dataTable>
                </h:form>

                <p:dialog header="编辑客流量" widgetVar="leadDialog"
                          modal="true" draggable="false" width="300" closeListener="#{leadManager.cancellCreate}">
                    <h:form id="form2">
                        <h:panelGrid columns="2" id="display">
                            <h:outputLabel value="序号:" for="id" />
                            <h:outputText id="id" value="#{leadManager.selectedLead.id}" title="Id"/>
                            <h:outputLabel value="男宾姓名:" for="mname" />
                            <h:inputText id="mname" value="#{leadManager.selectedLead.account.mname}" title="Mname" />
                            <h:outputLabel value="男宾电话:" for="mphone" />
                            <p:inputMask id="mphone" value="#{leadManager.selectedLead.account.mphone}" title="Mphone" mask="999999999" />
                            <h:outputLabel value="女宾姓名:" for="fname" />
                            <h:inputText id="fname" value="#{leadManager.selectedLead.account.fname}" title="Fname" />
                            <h:outputLabel value="女宾电话:" for="fphone" />
                            <p:inputMask id="fphone" value="#{leadManager.selectedLead.account.fphone}" title="Fphone" mask="999999999"/>
                            <h:outputLabel value="固定电话:" for="phone" />
                            <p:inputMask id="phone" value="#{leadManager.selectedLead.account.phone}" title="Phone" mask="9999999"/>
                            <h:outputLabel value="结婚日期:" for="marriageDate" />
                            <p:calendar id="marriageDate" value="#{leadManager.selectedLead.account.marriageDate}" pattern="yyyy-MM-dd" ></p:calendar>

                            <h:outputLabel value="客户来源:" for="source" />
                            <h:selectOneMenu id="source" value="#{leadManager.selectedLead.source}">
                                <f:selectItems value="#{applicationBean.sourceItems}"></f:selectItems>
                            </h:selectOneMenu>
                            <h:outputLabel value="来店意向:" for="inclination" />
                            <h:selectOneMenu id="inclination" value="#{leadManager.selectedLead.inclination}">
                                <f:selectItems value="#{applicationBean.inclinationItems}"></f:selectItems>
                            </h:selectOneMenu>
                            <h:outputLabel value="侧重点:" for="emphasis" />
                            <h:selectManyCheckbox id="emphasis" value="#{leadManager.selectedLead.emphasisArray}" layout="pageDirection" border="1">
                                <f:selectItems value="#{applicationBean.emphasisItems}"></f:selectItems>
                            </h:selectManyCheckbox>
                            <h:outputLabel value="客户级别:" for="rating" />
                            <p:rating id="rating" value="#{leadManager.selectedLead.rating}" />
                            <h:outputLabel value="来访时间:" for="visitTime" />
                            <p:calendar id="visitTime" value="#{leadManager.selectedLead.visitTime}" pattern="yyyy-MM-dd" requiredMessage="请填写来访日期"></p:calendar>
                            <f:facet name="footer">
                                <h:panelGroup>
                                    <p:commandButton value="保存" actionListener="#{leadManager.save}"  update="form1:leads,form:growl" oncomplete="handleSaveRequest(xhr, status, args)"></p:commandButton>
                                    <p:commandButton value="取消" onclick="leadDialog.hide()"></p:commandButton>
                                </h:panelGroup>
                            </f:facet>
                        </h:panelGrid>
                    </h:form>
                </p:dialog>


                <p:dialog widgetVar="accountDialog" modal="true" width="600" closeListener="#{leadManager.cancellCreate}" header="查询客户">
                    <h:form id ="form3">
                        <p:dataTable id="accounts" value="#{accountManager.accounts}" var="item" paginator="true" rows="20"
                                     selectionMode="single" selection="#{leadManager.selectedLead.account}"
                                     update="form2:display" onselectComplete="accountDialog.hide();leadDialog.show();" >
                            <f:facet name="header">
                                <h:panelGrid columns="4" style="width: 300px">
                                    <h:outputLabel value="模糊查询"></h:outputLabel>
                                    <h:inputText value="#{accountManager.searchContent}" title="可输入部分男宾或女宾的姓名与电话进行查询"></h:inputText>
                                    <p:commandLink update="form3:accounts" actionListener="#{accountManager.search}" title="查询">
                                        <p:graphicImage value="/resources/images/search.png"/>
                                    </p:commandLink>
                                    <p:ajaxStatus  style="width:16px;height:16px;">
                                        <f:facet name="start">
                                            <h:graphicImage  value="/resources/images/ajaxloading.gif" />
                                        </f:facet>
                                        <f:facet name="complete">
                                            <h:outputText value="" />
                                        </f:facet>
                                    </p:ajaxStatus>
                                </h:panelGrid>
                            </f:facet>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Id"/>
                                </f:facet>
                                <h:outputText value="#{item.id}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="男宾姓名"/>
                                </f:facet>
                                <h:outputText value="#{item.mname}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="男宾电话"/>
                                </f:facet>
                                <h:outputText value="#{item.mphone}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="女宾姓名"/>
                                </f:facet>
                                <h:outputText value="#{item.fname}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="女宾电话"/>
                                </f:facet>
                                <h:outputText value="#{item.fphone}">
                                    <f:convertDateTime pattern="MM/dd/yyyy" />
                                </h:outputText>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="固定电话"/>
                                </f:facet>
                                <h:outputText value="#{item.phone}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="结婚日期"/>
                                </f:facet>
                                <h:outputText value="#{item.marriageDate}">
                                    <f:convertDateTime pattern="MM/dd/yyyy" />
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                    </h:form>
                </p:dialog>
            </f:view>
        </ui:define>
    </ui:composition>
</html>
